<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>车服管理系统 - 登录</title>
    <script src="/js/vue.js"></script>
    <script src="/js/axios.js"></script>
    <script src="/element-ui/lib/index.js"></script>
    <link rel="stylesheet" href="/element-ui/lib/theme-chalk/index.css">
    <link href="/css/loginstyle.css" rel="stylesheet" type="text/css" media="all" />

    <style>
        #app{
            width: 100%;
            height: 95vh;
            /*background-image:url("/img/bg.png");*/
            background-size: cover;
            /*保持图片比例并完全覆盖元素*/
            background-position: center center;
            /*将图片居中对齐*/
        }
        .login-container {
            width: 100%;
            height: calc(60vh);
            position: relative;
            top: 30%;
        }

        .card {
            width: 440px;
            padding-bottom: 10px;
            margin: 0px auto;
            border-radius: 20px 3px;
            box-shadow: 3px 3px 10px #8c939d;
            background-color: rgba(255,255,255,.8);
        }

        .title {
            font-size: 24px;
            text-align: center;
            margin-bottom: 30px;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
        }

        .login-form {
            max-width: 400px;
            margin: 0 auto;
        }

        .login-btn {
            width: 78%;
            margin-left: 21%;
        }

        .btn-container {
            display: flex;
            justify-content: center;
        }
    </style>
</head>

<body>
    <div id="app" class="main-w3layouts wrapper">
        <div class="main-w3layouts wrapper">
            <div class="main-agileinfo">
                <el-card class="card agileits-top">
                    <h2 class="title">车服租赁系统运营管理后台</h2>
                    <el-form ref="loginForm" :model="loginForm" class="login-form" :rules="rules" label-position="right"
                             label-width="85px">
                        <el-form-item label="用户名：" prop="username">
                            <el-input type="text" v-model="loginForm.username" placeholder="请输入用户名" class="text">
                                <i slot="prefix" class="el-input__icon el-icon-user"></i>
                            </el-input>
                        </el-form-item>
                        <el-form-item label="密码：" prop="password">
                            <el-input type="password" v-model="loginForm.password" placeholder="请输入密码" class="text">
                                <i slot="prefix" class="el-input__icon el-icon-unlock"></i>
                            </el-input>
                        </el-form-item>
                    </el-form>
                    <div class="btn-container">
                        <el-button type="primary" class="login-btn" @click="login">登录</el-button>
                    </div>
                </el-card>
            </div>
            <ul class="w3lsg-bubbles">
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
            </ul>
        </div>

    </div>
    <script type="text/javascript">
        let vm = new Vue({
            el: "#app",
            data() {
                return {
                    loginForm: {
                        username: '',
                        password: ''
                    },
                    rules: {
                        username: [
                            { required: true, message: '请输入用户名', trigger: 'blur' }
                        ],
                        password: [
                            { required: true, message: '请输入密码', trigger: 'blur' }
                        ]
                    }
                }
            },
            methods: {
                login() {
                    this.$refs.loginForm.validate((valid) => {
                        if (valid) {
                            axios.post("/user/login", this.loginForm).then(resp => {
                            	let result = resp.data;
                                //登录成功
                                if (result.code) {
                                    //跳转到首页
                                    location.href = "/pages/main.html"
                                }
                                //登录失败
                            	else {
                                    this.$message.error(result.message);
                                }
                            });
                        } else {
                            return false;
                        }
                    });
                }
            }
        });
    </script>

</body>

</html>